package com.imooc.springboot.dubbo.consumer.transaction;

import com.alibaba.dubbo.config.annotation.Reference;
import com.imooc.springboot.dubbo.ServiceApi;
import org.mengyun.tcctransaction.api.Compensable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TransactionConsumer {
    @Autowired
    ServiceApi serviceApi;

    @Compensable(confirmMethod = "confirmSendMessage",cancelMethod = "cancelSendMessage",asyncCancel = true)
    public void sendMessage(String message){

        System.out.println("this is consumer sendMessage message = "+message);
//        message = serviceApi.sendMessage(message);
//        System.out.println(message);

        // 测试业务
        serviceApi.saveOrder("001",message,"5");
        serviceApi.isTrueSeats(message);
        serviceApi.isNotSold(message);
    }

    public void confirmSendMessage(String message){
        System.out.println("this is consumer confirmSendMessage message = "+message);

    }
    public void cancelSendMessage(String message){
        System.out.println("this is consumer cancelSendMessage message = "+message);

    }

}
